<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 用户列表 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.keyword" placeholder="输入用户昵称" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                :data="tableData"
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column label="用户头像">
                    <template slot-scope="scope">
                        <img
                            :src="scope.row.avatar"
                            alt=""
                            class="info-image"
                        />
                    </template>
                </el-table-column>
                <el-table-column prop="nickname" label="用户昵称"></el-table-column>      
                <el-table-column prop="phone" label="手机号">
                    <template slot-scope="scope">
                        {{ scope.row.phone ? scope.row.phone : '未填写' }}
                    </template>
                </el-table-column>
                <el-table-column prop="create_time" label="注册时间"></el-table-column>
                <el-table-column label="管理" >
                    <template slot-scope="scope">
                    <el-button type="success" size="small" v-if="scope.row.status==0" @click="modifyStatus(scope.row.uid,1)">启用</el-button>
                    <el-button type="danger" size="small" v-if="scope.row.status==1" @click="modifyStatus(scope.row.uid,0)">停用</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.page"
                    :page-size="query.rows"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { userListData,modifyUserStatus } from '../../api/index';
export default {
    // name: 'user_list',
    data() {
        return {
            query: {
                page: 1,
                rows: 4,
                keyword: ''
            },
            tableData: [],
            pageTotal: 0
        };
    },
    created() {
        this.getData();
    },
    methods: {
        getData() {
            userListData(this.query).then((res) => {
                console.log(res);
                this.tableData = res.data.list;
                this.pageTotal = res.data.count;
            });
        },
        //搜索
        handleSearch() {
            this.$set(this.query);
            this.getData();
        },
        // 分页
        handlePageChange(val) {
            this.$set(this.query, 'page', val);
            this.getData();
        },
       async modifyStatus(uid,status){
           let res=await modifyUserStatus({uid,status});
           console.log(res);
           if(res.code==1){
             this.getData();
           }else{
            console.log('修改失败')
           }
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
    float: right;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}

.mr10 {
    margin-right: 10px;
}

.info-image {
    width: 60px;
    height: 60px;
    border-radius: 50%;
}
</style>
